package com.showsu.editor.utils;

import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Type;
import java.util.List;

/**
 * @Author: William
 * @Description: gson反序列化，忽略
 * @Date: Created in 9:33 上午 2024/8/14
 * @Modified By:
 */
@Slf4j
public class GsonFailSafeArrayJsonDeserializer implements JsonDeserializer<List<?>> {
    @Override
    public List<?> deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
        try {
            if (jsonElement != null && jsonElement.isJsonArray()) {
                Gson gson = new Gson();
                return gson.fromJson(jsonElement, type);
            }
        } catch (Exception e) {
            log.error("GsonFailSafeArrayJsonDeserializer deserialize error", e);
        }
        return null;
    }
}
